﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace PCS_Linh.lab03
{
    class DescendingArray
    {
        public void run()
        {
            ////nhap so phan tu cua mang
            //Console.Write("Nhap so phan tu cua mang: ");
            //int n = Convert.ToInt32(Console.ReadLine());
            //int[] a = new int[n];

            ////nhap so
            //Console.WriteLine("Nhap so: ");

            //for (int i = 0; i < n; i++)
            //{
            //    Console.Write("a[{0}]: ", i);
            //    a[i] = Convert.ToInt32(Console.ReadLine());
                
            //}
            //Console.WriteLine();

            ////mang la
            //Console.WriteLine("Mang la: ");
            //for (int i = 0; i < n; i++)
            //{
            //    Console.Write(a[i] + " ");
            //}
            //Console.WriteLine();

            ////sap xep giam dan
            //Console.WriteLine("Mang sau khi sap xep giam dan: ");
            //for (int i = 0; i < a.Length-1; i++)
            //{
            //    for (int j = i+1; j < a.Length; j++)
            //    {
            //        if (a[i] < a[j])
            //        {
            //          int tam = a[i];
            //            a[i] = a[j];
            //            a[j] = tam;
            //        }
            //    }
               
            //}

            //for (int i = 0; i < n; i++)
            //{
            //    Console.Write(a[i] + " ");
            //}

            ////cach 2
            //nhap so phan tu cua mang
            Console.Write("Nhap so phan tu cua mang: ");
            int n = Convert.ToInt32(Console.ReadLine());
            Array a = Array.CreateInstance(typeof(int), n);

            //nhap so
            Console.WriteLine("Nhap so: ");

            for (int i = 0; i < n; i++)
            {
                Console.Write("a[{0}]: ", i);
                a.SetValue(Convert.ToInt32(Console.ReadLine()), i);
            }
            Console.WriteLine();

            //mang la
            Console.Write("Mang la: ");
            foreach (int item in a)
            {
                Console.Write(item +" ");
            }

            //for (int i = 0; i < n; i++)
            //{
            //    Console.Write(a.GetValue(i) + " "); ;
            //}

            // xap sep 
            Array.Sort(a);
            //mang la
            Console.Write("\nMang sau khi sap xep (asc): ");
            foreach (int item in a)
            {
                Console.Write(item + " ");
            }

            Array.Reverse(a);

            //mang la
            Console.Write("\nMang sau khi reverse: ");
            foreach (int item in a)
            {
                Console.Write(item + " ");
            }
        }
    }
}
